import { Component } from '@angular/core';
import { Role } from './role';

import { OnInit } from '@angular/core';
import { Router } from '@angular/router';

import { RoleService } from './role.service';

@Component({
  selector: 'my-roles',
  templateUrl: './role.component.html'
})

export class RoleComponent implements OnInit {
  ngOnInit() {
    this.getRoles();
  }

  roles: Role[];
  selectedRole: Role;

  onSelect(role: Role) { this.selectedRole = role; }
  onNew() {
    this.selectedRole = new Role();
  }
  
  constructor(
    private router: Router,
    private roleService: RoleService) {
  }

  getRoles() {
    this.roleService.getRoles().then(roles => this.roles = roles);
  }
}
